﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.Common;
using Mocola.BLL;
using Mocola.Model;

namespace Mocola.Net.Web.Utility
{
    /*Begin:[#21]*/  
    public class NavigateTree
    {
        private void BindNavigateTree(TreeNode root,string parentID,DataTable dt)
        {
            string filter = "ParentID=" + parentID;
            DataRow [] rows=dt.Select(filter);
            foreach(DataRow row in rows)
            {
                TreeNode node=new TreeNode ();
                node.Value = row["uniqueid"].ToString() + "|" + row["ExtId"].ToString() + "|" + row["type"].ToString();            
                node.Text = row["name"].ToString();                
                root.ChildNodes.Add (node);                
                BindNavigateTree(node,row["uniqueid"].ToString (),dt);
            }
        }

        private DataTable GetMoc_TreeAsTable()
        {
           using (DataTable dt=Databases.MocolaNet.Select(Moc_TreesInfo.Moc_Trees,
                Moc_TreesInfo.Moc_Trees.Name,
                Moc_TreesInfo.Moc_Trees.UniqueID,
                Moc_TreesInfo.Moc_Trees.ParentID,
                Moc_TreesInfo.Moc_Trees.Type,
                Moc_TreesInfo.Moc_Trees.ExtId)
                .ToDataSet().Tables[0])
            {
               return dt;
            }
        }
        private DataTable GetMoc_MTreeAsTable()
        {
            using (DataTable dt = Databases.MocolaNet.Select(Moc_MTreesInfo.Moc_MTrees,
                 Moc_MTreesInfo.Moc_MTrees.Name,
                 Moc_MTreesInfo.Moc_MTrees.UniqueID,
                 Moc_MTreesInfo.Moc_MTrees.ParentID,
                 Moc_MTreesInfo.Moc_MTrees.Type,
                 Moc_MTreesInfo.Moc_MTrees.ExtId)
                 .ToDataSet().Tables[0])
            {
                return dt;
            }
        }
        /// <summary>
        /// 项目结构树
        /// </summary>
        /// <param name="tr"></param>
        public void InitMoc_Tree(TreeView tr, string ParentID)
        {
            TreeNode root=new TreeNode ("项目类");
            BindNavigateTree(root, ParentID, GetMoc_TreeAsTable());
            tr.Attributes.Add("onclick", "return getNode(event);");
            tr.Nodes.Add(root);
        }

        /// <summary>
        /// 管理结构树
        /// </summary>
        /// <param name="tr"></param>
        public void InitMoc_MTree(TreeView tr, string ParentID)
        {
            TreeNode root = new TreeNode("管理类");
            BindNavigateTree(root, ParentID, GetMoc_MTreeAsTable());
            tr.Attributes.Add("onclick", "return getNode(event);");
            tr.Nodes.Add(root);
        }  

    }
    /*End:[#21]*/
}
